<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="true" border="false">
          <div class="table-page-search-wrapper">
            <a-form layout="inline">
              <a-row :gutter="24">
                <a-col :span="8">
                  <a-form-item :label="i18n('form.templateName','模板名称')">
                    <a-input :placeholder="i18n('form.templateName','模板名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item :label="$ti18('rxForm.rxAlias','别名')">
                    <a-input :placeholder="$ti18('rxForm.rxAlias','别名','','input')" v-model="queryParam.Q_ALIAS__S_LK"/>
                  </a-form-item>
                </a-col>
                <template v-if="advanced">

                </template>
                <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button @click="$refs.table.loadData()" icon="search" type="primary">{{$ti18('rxList.searchBtn','查询')}}</a-button>
                <a-button @click="resetSearchList" style="margin-left: 4px">{{$ti18('rxList.resetBtn','重置')}}</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? $ti18('rxList.putAwayBtn','收起') : $ti18('rxList.openBtn','展开') }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <div class="table-operator">
            <a-button v-if="allowEdit" type="primary" icon="plus" @click="addPrint">{{$ti18('rxList.newBtn','新建')}}</a-button>
            <a-button v-if="allowEdit && editEnable && selectedRowKeys.length > 0" type="primary" icon="edit" @click="editOnePrint">{{$ti18('rxList.editBtn','编辑')}}
            </a-button>
            <a-dropdown v-if="allowEdit && removeEnable && selectedRowKeys.length > 0">
              <a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}</a-button>
            </a-dropdown>
          </div>
        </div>
        <rx-grid
          ref="table"
          :allowRowSelect="true"
          :multiSelect="true"
          :columns="columns"
          :defaultPageSize="10"
          url="/api-form/form/core/formPdfTemplate/query"
          :queryParam="queryParam"
          data-field="result.data"
          :pageSizeOptions="['10','30','40']"
          id-field="id"
          @selectChange="onSelectChange"
        >
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span v-if="allowEdit && editEnable" @click.stop="editPrint(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
            <span v-if="allowEdit && removeEnable" @click.stop="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
            <span v-if="!allowEdit" @click="selectPrint(record)">{{$ti18('rxList.select','选择')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import FormPrintLodopApi from '@/api/form/core/formPrintLodop'
  import FormPrintLodopEdit from './FormPrintLodopEdit'
  import {BaseList, Util} from "@lowcode/jpaas-common-lib";
  export default {
    name: 'FormPDFList',
    mixins: [BaseList],
    props:["layerid","destroy","formId","formName","boDefId","allowEdit"],
    data() {
      return {
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 100,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: this.i18n('form.templateName','模板名称'), dataIndex: 'name', width: 100},
          {title: this.$ti18('rxForm.rxAlias','别名'), dataIndex: 'key', width: 100},
          {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],
        component:FormPrintLodopEdit,
        comment:this.i18n('list.formPdfTemp','表单PDF模板'),
        widthHeight:['800px','600px']
      }
    },
    created() {
      this.queryParam['Q_BO_DEF_ID__S_EQ'] = this.boDefId;
    },
    methods:{
      i18n(name,text,key){
          return this.$ti18(name,text,"pdfTemplate",key);
      },
      resetSearchList () {
        this.$nextTick(()=>{
          this.queryParam={Q_FORM_ID__S_EQ:this.formId};
          this.$nextTick(()=>{
            this.$refs[this.table].loadData();
          })
        })
      },
      delById(ids){
        return FormPrintLodopApi.del({ ids: ids.join(',') });
      },
      getListByParams(parameter){
        return FormPrintLodopApi.query(parameter)
      },
      selectPrint(record){
        Util.closeWindow(this,"ok",record);
      },
      addPrint(){
        var self_ = this;
        var baseConf = {
          curVm: self_,
          component: this.component,
          title: self_.$ti18('rxList.newBtn','添加') + this.comment,
          max:true,
          data: {formId: self_.formId,formName:self_.formName,boDefId:self_.boDefId}
        };
        Util.open(baseConf, function (action) {
          if (action == "ok") {
            self_.refreshGrid();
          }
        });
      },
      editPrint(record){
        var conf={
          component:this.component,
          title:this.$ti18('rxList.editBtn','编辑') + this.comment,
          max:true,
          data: {pkId:record.pkId,boDefId:this.boDefId}
        };
        this.handleEdit(conf);
      },
      editOnePrint(){
        var conf={
          component:this.component,
          title:this.$ti18('rxList.editBtn','编辑') +this.comment,
          max:true
        };
        if(this.selectedRows.length>0){
          conf.data={pkId:this.selectedRows[0].pkId,boDefId:this.boDefId};
          this.handleEdit(conf)
        }
      }
    }
  }
</script>
<style scoped>

</style>

